package com.sskj.data;

import java.time.*;
import java.util.Date;

/**
 * @Author: Like
 * @Date: 2023/12/18 16:21
 * @Description:
 */
public class Demo {
    public static void main(String[] args) {
        //现在的时间
        LocalDateTime now = LocalDateTime.now();
        for (int i = 1; i < 8; i++) {
            //今天的最后一秒 2023-12-18T23:59:59.999999999
            LocalDateTime dateTime = now.minusDays(i);
            LocalDateTime with = dateTime.with(LocalTime.MAX);
            //今天最后一秒-30秒
            LocalDateTime localDateTime = with.minusSeconds(30);
        }

        LocalDate today = LocalDate.now();
        System.out.println(today.toString());
    }

    // 获得某天最大时间 2022-12-09 23:59:59
    public static Date getEndOfDay(Long date) {
        LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date), ZoneId.systemDefault());
        LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX);
        return Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
    }

    // 获得某天最小时间 2022-12-09 00:00:00
    public static Date getStartOfDay(Date date) {
        LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
        LocalDateTime startOfDay = localDateTime.with(LocalTime.MIN);
        return Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
    }


}